package org.example.rzfx.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.rzfx.entity.LogSource;
import org.example.rzfx.mapper.LogSourceMapper;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;

/**
 * 日志采集源服务
 */
@Service
public class LogSourceService extends ServiceImpl<LogSourceMapper, LogSource> {
    
    /**
     * 更新心跳时间
     */
    public void updateHeartbeat(Long sourceId) {
        LogSource source = this.getById(sourceId);
        if (source != null) {
            source.setLastHeartbeat(LocalDateTime.now());
            this.updateById(source);
        }
    }
    
    /**
     * 更新采集偏移量
     */
    public void updateOffset(Long sourceId, Long offset) {
        LogSource source = this.getById(sourceId);
        if (source != null) {
            source.setLastOffset(offset);
            source.setLastHeartbeat(LocalDateTime.now());
            this.updateById(source);
        }
    }
}

